<?php
ini_set("display_errors", "On"); 
ini_set("max_execution_time", "300"); 
require_once("../common/SearchPath.php");
require_once(SEARCHLIBPATH."db.class.php");
require_once(SEARCHPOPATH."LinkPO.php");
require_once(SEARCHPOPATH."ModPO.php");
require_once(SEARCHPOPATH."HistoryPO.php");
require_once(SEARCHPOPATH."SLogPO.php");
require_once(SEARCHVOPATH."LinkVO.php");
require_once(SEARCHVOPATH."ModVO.php");
require_once(SEARCHVOPATH."HistoryVO.php");
require_once(SEARCHVOPATH."SLogVO.php");
require_once(SEARCHDAOPATH."LinkDAO.php");
require_once(SEARCHDAOPATH."ModDAO.php");
require_once(SEARCHDAOPATH."HistoryDAO.php");
require_once(SEARCHDAOPATH."SLogDAO.php");
require_once(SEARCHBIZPATH."LinkBiz.php");
require_once(SEARCHBIZPATH."ModBiz.php");
require_once(SEARCHBIZPATH."HistoryBiz.php");
require_once(SEARCHBIZPATH."SLogBiz.php");
require_once(SEARCHLIBPATH."array.class.php");
require_once(SEARCHLIBPATH."format.class.php");
require_once(SEARCHLIBPATH."page.class.php");
require_once(SEARCHLIBPATH."httpd.class.php");
require_once(SEARCHLIBPATH."phpanalysis.class.php");
require_once("spider_config.php");
session_start();
$endid = 0;
if(!isset($_GET['action'])){
	echo '<html>';
	echo '<head>';
	echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
	echo '<title>管理 - 爱贝搜索</title>';
	echo '</head>';
	echo '<div style="width:100%;text-align:center;margin-top:200px;font-size:12px;">';
	echo '<div style="text-align:left;width:300px;border:1px solid rgb(240, 240, 241);margin:auto;padding:20px;">';
	echo '<form action="?action=login" method="post">';
	echo '账号：<input type="text" name="username" /><br />';
	echo '密码：<input type="password" name="password" /><br />';
	echo '<input type="submit" value="登录" style="margin:10px auto auto 40px;width:60px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="../" style="color:rgb(78, 28, 235);text-decoration:none;">返回首页</a>';
	echo '</form>';
	echo '</div>';
	echo '</div>';
	echo '</html>';
	exit();
}else if(isset($_GET['action']) && $_GET['action']=="login"){
	if($_POST['username']=='likewatch' && $_POST['password']=='qwermikeokleilei'){
		$_SESSION["login"] = 'true';
		header("Location:?action=main");
	}else{
		header("Location:.");
	}
	exit();
}else if(isset($_GET['action'])){
	if(isset($_SESSION['login']) && $_SESSION['login']=='true'){
		if($_GET['action']=="main"){
			echo '<html>';
			echo '<head>';
			echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
			echo '<title>管理 - 爱贝搜索</title>';
			echo '</head>';
			echo '<div style="width:100%;text-align:center;margin-top:200px;font-size:12px;">';
			echo '<div style="text-align:left;width:200px;border:1px solid rgb(240, 240, 241);margin:auto;padding:20px;">';
			echo '请选择索引模块：<br /><br /><a href="?action=spider&mod=1" style="color:rgb(78, 28, 235);">文章</a><br /><br /><a href="?action=spider&mod=2" style="color:rgb(78, 28, 235);">帖子</a><br /><br /><a href="?action=spider&mod=3" style="color:rgb(78, 28, 235);">日志</a><br /><br /><a href="?action=spider&mod=4" style="color:rgb(78, 28, 235);">相册</a><br /><br /><a href="?action=spider&mod=5" style="color:rgb(78, 28, 235);">圈子</a>';
			echo '</div>';
			echo '</div>';
			echo '</html>';
		}else if($_GET['action']=="spider"){
			switch ($_GET['mod']){
				case 1:
					if(!isset($_GET['start'])){
						echo '<html>';
						echo '<head>';
						echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
						echo '<title>管理 - 爱贝搜索</title>';
						echo '</head>';
						echo '<div style="width:100%;text-align:center;margin-top:200px;font-size:12px;">';
						echo '<div style="text-align:left;width:300px;border:1px solid rgb(240, 240, 241);margin:auto;padding:20px;">';
						echo '建立文章索引：<br /><br />';
						echo '<form action="">';
						echo '<input type="hidden" name="action" value="spider" />';
						echo '<input type="hidden" name="mod" value="1" />';
						echo '<input type="hidden" name="page" value="1" />';
						echo '开始 ID：<input type="text" name="start" value="'.$mod_1.'" style="width:50px;" />&nbsp;&nbsp;';
						echo '结束 ID：<input type="text" name="end" style="width:50px;" /><br />';
						echo '每页生成：<input type="text" name="size" value="500" maxlength="3" style="width:50px;" />';
						echo '<input type="submit" value="开始" style="margin:10px auto auto 40px;width:60px;" /><br /><br />' .
								'<input type="radio" name="op" value="add" checked="checked" /> 新增索引' .
								'<input type="radio" name="op" value="update" /> 更新索引' .
								'<a href="?action=main" style="color:rgb(78, 28, 235);display:block;float:right;">返回上级</a>';
						echo '</form>';
						echo '</div>';
						echo '</div>';
						echo '</html>';
					}else{
						$start = $_GET['start'];
						$end = $_GET['end'];
						$end = $end<0 || $end==""?$end=999999999999:$end;
						$size = $_GET['size'];
						$page = $_GET['page'];
						$op = $_GET['op'];
						$mysql_start = ($page-1)*$size+$start;
						$mysql_start=$mysql_start<0?0:$mysql_start;
						$mysql_end = $mysql_start+$size;
						$mysql_end = $mysql_end>$end?$end:$mysql_end;
						if($mysql_start<=$end){
							$isEnd = spiderArticle($mysql_start,$mysql_end,$op);
						}else{
							$isEnd = false;
						}
						if($isEnd){
							echo $mysql_start.'-'.$mysql_end.' Finished!<br /><a href="?action=spider&mod=1&start='.$start.'&end='.$end.'&size='.$size.'&op='.$op.'&page='.($page+1).'">continue</a>';
							echo '<script>window.location="?action=spider&mod=1&start='.$start.'&end='.$end.'&size='.$size.'&op='.$op.'&page='.($page+1).'"</script>';
						}else{
							echo "end - <a href='?action=spider&mod=1'>back</a>";
						}
					}
					break;
				case 2:
					if(!isset($_GET['start'])){
						echo '<html>';
						echo '<head>';
						echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
						echo '<title>管理 - 爱贝搜索</title>';
						echo '</head>';
						echo '<div style="width:100%;text-align:center;margin-top:200px;font-size:12px;">';
						echo '<div style="text-align:left;width:300px;border:1px solid rgb(240, 240, 241);margin:auto;padding:20px;">';
						echo '建立帖子索引：<br /><br />';
						echo '<form action="">';
						echo '<input type="hidden" name="action" value="spider" />';
						echo '<input type="hidden" name="mod" value="2" />';
						echo '<input type="hidden" name="page" value="1" />';
						echo '开始 ID：<input type="text" name="start" value="'.$mod_2.'" style="width:50px;" />&nbsp;&nbsp;';
						echo '结束 ID：<input type="text" name="end" style="width:50px;" /><br />';
						echo '每页生成：<input type="text" name="size" value="500" maxlength="3" style="width:50px;" />';
						echo '<input type="submit" value="开始" style="margin:10px auto auto 40px;width:60px;" /><br /><br />' .
								'<input type="radio" name="op" value="add" checked="checked" /> 新增索引' .
								'<input type="radio" name="op" value="update" /> 更新索引' .
								'<a href="?action=main" style="color:rgb(78, 28, 235);display:block;float:right;">返回上级</a>';
						echo '</form>';
						echo '</div>';
						echo '</div>';
						echo '</html>';
					}else{
						$start = $_GET['start'];
						$end = $_GET['end'];
						$end = $end<0 || $end==""?$end=999999999999:$end;
						$size = $_GET['size'];
						$page = $_GET['page'];
						$op = $_GET['op'];
						$mysql_start = ($page-1)*$size+$start;
						$mysql_start=$mysql_start<0?0:$mysql_start;
						$mysql_end = $mysql_start+$size;
						$mysql_end = $mysql_end>$end?$end:$mysql_end;
						if($mysql_start<=$end){
							$isEnd = spiderBbs($mysql_start,$mysql_end,$op);
						}else{
							$isEnd = false;
						}
						if($isEnd){
							echo $mysql_start.'-'.$mysql_end.' Finished!<br /><a href="?action=spider&mod=2&start='.$start.'&end='.$end.'&size='.$size.'&op='.$op.'&page='.($page+1).'">continue</a>';
							echo '<script>window.location="?action=spider&mod=2&start='.$start.'&end='.$end.'&size='.$size.'&op='.$op.'&page='.($page+1).'"</script>';
						}else{
							echo "end - <a href='?action=spider&mod=2'>back</a>";
						}
					}
					break;
				case 3:
					if(!isset($_GET['start'])){
						echo '<html>';
						echo '<head>';
						echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
						echo '<title>管理 - 爱贝搜索</title>';
						echo '</head>';
						echo '<div style="width:100%;text-align:center;margin-top:200px;font-size:12px;">';
						echo '<div style="text-align:left;width:300px;border:1px solid rgb(240, 240, 241);margin:auto;padding:20px;">';
						echo '建立日志索引：<br /><br />';
						echo '<form action="">';
						echo '<input type="hidden" name="action" value="spider" />';
						echo '<input type="hidden" name="mod" value="3" />';
						echo '<input type="hidden" name="page" value="1" />';
						echo '开始 ID：<input type="text" name="start" value="'.$mod_3.'" style="width:50px;" />&nbsp;&nbsp;';
						echo '结束 ID：<input type="text" name="end" style="width:50px;" /><br />';
						echo '每页生成：<input type="text" name="size" value="500" maxlength="3" style="width:50px;" />';
						echo '<input type="submit" value="开始" style="margin:10px auto auto 40px;width:60px;" /><br /><br />' .
								'<input type="radio" name="op" value="add" checked="checked" /> 新增索引' .
								'<input type="radio" name="op" value="update" /> 更新索引' .
								'<a href="?action=main" style="color:rgb(78, 28, 235);display:block;float:right;">返回上级</a>';
						echo '</form>';
						echo '</div>';
						echo '</div>';
						echo '</html>';
					}else{
						$start = $_GET['start'];
						$end = $_GET['end'];
						$end = $end<0 || $end==""?$end=999999999999:$end;
						$size = $_GET['size'];
						$page = $_GET['page'];
						$op = $_GET['op'];
						$mysql_start = ($page-1)*$size+$start;
						$mysql_start=$mysql_start<0?0:$mysql_start;
						$mysql_end = $mysql_start+$size;
						$mysql_end = $mysql_end>$end?$end:$mysql_end;
						if($mysql_start<=$end){
							$isEnd = spiderBlog($mysql_start,$mysql_end,$op);
						}else{
							$isEnd = false;
						}
						if($isEnd){
							echo $mysql_start.'-'.$mysql_end.' Finished!<br /><a href="?action=spider&mod=3&start='.$start.'&end='.$end.'&size='.$size.'&op='.$op.'&page='.($page+1).'">continue</a>';
							echo '<script>window.location="?action=spider&mod=3&start='.$start.'&end='.$end.'&size='.$size.'&op='.$op.'&page='.($page+1).'"</script>';
						}else{
							echo "end - <a href='?action=spider&mod=3'>back</a>";
						}
					}
					break;
				case 4:
					if(!isset($_GET['start'])){
						echo '<html>';
						echo '<head>';
						echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
						echo '<title>管理 - 爱贝搜索</title>';
						echo '</head>';
						echo '<div style="width:100%;text-align:center;margin-top:200px;font-size:12px;">';
						echo '<div style="text-align:left;width:300px;border:1px solid rgb(240, 240, 241);margin:auto;padding:20px;">';
						echo '建立相册索引：<br /><br />';
						echo '<form action="">';
						echo '<input type="hidden" name="action" value="spider" />';
						echo '<input type="hidden" name="mod" value="4" />';
						echo '<input type="hidden" name="page" value="1" />';
						echo '开始 ID：<input type="text" name="start" value="'.$mod_4.'" style="width:50px;" />&nbsp;&nbsp;';
						echo '结束 ID：<input type="text" name="end" style="width:50px;" /><br />';
						echo '每页生成：<input type="text" name="size" value="500" maxlength="3" style="width:50px;" />';
						echo '<input type="submit" value="开始" style="margin:10px auto auto 40px;width:60px;" /><br /><br />' .
								'<input type="radio" name="op" value="add" checked="checked" /> 新增索引' .
								'<input type="radio" name="op" value="update" /> 更新索引' .
								'<a href="?action=main" style="color:rgb(78, 28, 235);display:block;float:right;">返回上级</a>';
						echo '</form>';
						echo '</div>';
						echo '</div>';
						echo '</html>';
					}else{
						$start = $_GET['start'];
						$end = $_GET['end'];
						$end = $end<0 || $end==""?$end=999999999999:$end;
						$size = $_GET['size'];
						$page = $_GET['page'];
						$op = $_GET['op'];
						$mysql_start = ($page-1)*$size+$start;
						$mysql_start=$mysql_start<0?0:$mysql_start;
						$mysql_end = $mysql_start+$size;
						$mysql_end = $mysql_end>$end?$end:$mysql_end;
						if($mysql_start<=$end){
							$isEnd = spiderAlbum($mysql_start,$mysql_end,$op);
						}else{
							$isEnd = false;
						}
						if($isEnd){
							echo $mysql_start.'-'.$mysql_end.' Finished!<br /><a href="?action=spider&mod=4&start='.$start.'&end='.$end.'&size='.$size.'&op='.$op.'&page='.($page+1).'">continue</a>';
							echo '<script>window.location="?action=spider&mod=4&start='.$start.'&end='.$end.'&size='.$size.'&op='.$op.'&page='.($page+1).'"</script>';
						}else{
							echo "end - <a href='?action=spider&mod=4'>back</a>";
						}
					}
					break;
				case 5:
					if(!isset($_GET['start'])){
						echo '<html>';
						echo '<head>';
						echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
						echo '<title>管理 - 爱贝搜索</title>';
						echo '</head>';
						echo '<div style="width:100%;text-align:center;margin-top:200px;font-size:12px;">';
						echo '<div style="text-align:left;width:300px;border:1px solid rgb(240, 240, 241);margin:auto;padding:20px;">';
						echo '建立圈子索引：<br /><br />';
						echo '<form action="">';
						echo '<input type="hidden" name="action" value="spider" />';
						echo '<input type="hidden" name="mod" value="5" />';
						echo '<input type="hidden" name="page" value="1" />';
						echo '开始 ID：<input type="text" name="start" value="'.$mod_5.'" style="width:50px;" />&nbsp;&nbsp;';
						echo '结束 ID：<input type="text" name="end" style="width:50px;" /><br />';
						echo '每页生成：<input type="text" name="size" value="500" maxlength="3" style="width:50px;" />';
						echo '<input type="submit" value="开始" style="margin:10px auto auto 40px;width:60px;" /><br /><br />' .
								'<input type="radio" name="op" value="add" checked="checked" /> 新增索引' .
								'<input type="radio" name="op" value="update" /> 更新索引' .
								'<a href="?action=main" style="color:rgb(78, 28, 235);display:block;float:right;">返回上级</a>';
						echo '</form>';
						echo '</div>';
						echo '</div>';
						echo '</html>';
					}else{
						$start = $_GET['start'];
						$end = $_GET['end'];
						$end = $end<0 || $end==""?$end=999999999999:$end;
						$size = $_GET['size'];
						$page = $_GET['page'];
						$op = $_GET['op'];
						$mysql_start = ($page-1)*$size+$start;
						$mysql_start=$mysql_start<0?0:$mysql_start;
						$mysql_end = $mysql_start+$size;
						$mysql_end = $mysql_end>$end?$end:$mysql_end;
						if($mysql_start<=$end){
							$isEnd = spiderGroup($mysql_start,$mysql_end,$op);
						}else{
							$isEnd = false;
						}
						if($isEnd){
							echo $mysql_start.'-'.$mysql_end.' Finished!<br /><a href="?action=spider&mod=5&start='.$start.'&end='.$end.'&size='.$size.'&op='.$op.'&page='.($page+1).'">continue</a>';
							echo '<script>window.location="?action=spider&mod=5&start='.$start.'&end='.$end.'&size='.$size.'&op='.$op.'&page='.($page+1).'"</script>';
						}else{
							echo "end - <a href='?action=spider&mod=5'>back</a>";
						}
					}
					break;
			}
		}
	}else{
		header("Location:.");
		exit();
	}
	exit();
}

//记录索引记录
function write_spider_config($mod_1,$mod_2,$mod_3,$mod_4,$mod_5){
	$content = '<?php'."\n".'$mod_1='.$mod_1.';'."\n".'$mod_2='.$mod_2.';'."\n".'$mod_3='.$mod_3.';'."\n".'$mod_4='.$mod_4.';'."\n".'$mod_5='.$mod_5.';'."\n".'?>';
	file_put_contents('spider_config.php',$content);
}

/**
 * 判断是否结束
 */
function isEnd($Operate,$sql){
	$result = $Operate -> get_one($sql);
	global $endid;
	if($result['id']!=null && $result['id']!=''){	
		$endid = $result['id'];
		return false;
	}else{
		return true;
	}
}

//文章
function spiderArticle($start,$end,$action='add'){
	$Operate=new Operate();
	$Operate -> connect('127.0.0.1','root','root','ibeicom',1,'gbk');
	$result=$Operate->get_all("select * from dede_addonarticle as a,dede_archives as b where a.aid=b.id and a.aid>=".$start." and a.aid<".$end);
	$format = new format();
	$array = new ArraySet();
	$endidtemp = 0;
	for($i=0;$i<count($result);$i++){
		$linkVO = new LinkVO();
		$linkVO -> setTitle($format -> removeHtml(mb_convert_encoding($result[$i]['title'],'utf-8','gbk')));
		$linkVO -> setContent($format -> removeHtml(mb_convert_encoding($result[$i]['body'],'utf-8','gbk')));
		$linkVO -> setUrl('http://www.i-bei.com/toarticle.php?id='.mb_convert_encoding($result[$i]['id'],'utf-8','gbk'));
		$linkVO -> setTime($result[$i]['pubdate']);
		$linkVO -> setMod(1);
		$array -> add($linkVO);
		$endidtemp = $result[$i]['id'];
	}
	$linkBiz = new LinkBiz();
	if($action=='add'){
		$linkBiz -> addArraySet($array);
	}else{
		$linkBiz -> updateArraySet($array);
	}
	$sql_next = "select a.aid as id from dede_addonarticle as a,dede_archives as b where a.aid=b.id and a.aid>=".$end.' order by a.aid asc limit 1';
	global $mod_1,$mod_2,$mod_3,$mod_4,$mod_5,$endid;
	if(isEnd($Operate,$sql_next)){
		if($endidtemp!=0)write_spider_config($endidtemp,$mod_2,$mod_3,$mod_4,$mod_5);
		return false;
	}else{
		if($endid!=0)write_spider_config($endid,$mod_2,$mod_3,$mod_4,$mod_5);
		return true;
	}
}

//帖子
function spiderBbs($start,$end,$action='add'){
	$Operate=new Operate();
	$Operate -> connect('127.0.0.1','root','root','bbs',1,'gbk');
	$result=$Operate->get_all("select * from pre_forum_thread where tid>=".$start." and tid<".$end." order by tid asc");
	$format = new format();
	$array = new ArraySet();
	$endidtemp = 0;
	for($i=0;$i<count($result);$i++){
		$post=$Operate->get_all("select * from pre_forum_post where tid=".$result[$i]['tid']." order by pid");
		if(count($post)>0){
			$content = "";
			for($j=0;$j<count($post);$j++){
				$content .= $post[$j]['message'];
			}
			$content = $format -> removeDZCode($content);
			$linkVO = new LinkVO();
			$linkVO -> setTitle($format -> removeHtml(mb_convert_encoding($result[$i]['subject'],'utf-8','gbk')));
			$linkVO -> setContent($format -> removeHtml(mb_convert_encoding($content,'utf-8','gbk')));
			$linkVO -> setUrl('http://www.i-bei.com/baby/thread-'.mb_convert_encoding($result[$i]['tid'],'utf-8','gbk')."-1-1.html");
			$linkVO -> setTime($result[$i]['dateline']);
			$linkVO -> setMod(2);
			$array -> add($linkVO);
			$endidtemp = $result[$i]['tid'];
		}
	}
	$linkBiz = new LinkBiz();
	if($action=='add'){
		$linkBiz -> addArraySet($array);
	}else{
		$linkBiz -> updateArraySet($array);
	}
	$sql_next = "select tid as id from pre_forum_thread where tid>=".$end.' order by tid asc limit 1';
	global $mod_1,$mod_2,$mod_3,$mod_4,$mod_5,$endid;
	if(isEnd($Operate,$sql_next)){
		if($endidtemp!=0)write_spider_config($mod_1,$endidtemp,$mod_3,$mod_4,$mod_5);
		return false;
	}else{
		if($endid!=0)write_spider_config($mod_1,$endid,$mod_3,$mod_4,$mod_5);
		return true;
	}
}

//日志
function spiderBlog($start,$end,$action='add'){
	$Operate=new Operate();
	$Operate -> connect('127.0.0.1','root','root','bbs',1,'gbk');
	$result=$Operate->get_all("select * from pre_home_blog as a,pre_home_blogfield as b where a.blogid=b.blogid and a.blogid>=".$start." and a.blogid<".$end);
	$format = new format();
	$array = new ArraySet();
	$endidtemp = 0;
	for($i=0;$i<count($result);$i++){
		$linkVO = new LinkVO();
		$linkVO -> setTitle($format -> removeHtml(mb_convert_encoding($result[$i]['subject'],'utf-8','gbk')));
		$linkVO -> setContent($format -> removeHtml(mb_convert_encoding($result[$i]['message'],'utf-8','gbk')));
		$linkVO -> setUrl('http://www.i-bei.com/baby/home.php?mod=space&uid='.mb_convert_encoding($result[$i]['uid'],'utf-8','gbk').'&do=blog&id='.mb_convert_encoding($result[$i]['blogid'],'utf-8','gbk'));
		$linkVO -> setTime($result[$i]['dateline']);
		$linkVO -> setMod(3);
		$array -> add($linkVO);
		$endidtemp = $result[$i]['blogid'];
	}
	$linkBiz = new LinkBiz();
	if($action=='add'){
		$linkBiz -> addArraySet($array);
	}else{
		$linkBiz -> updateArraySet($array);
	}
	$sql_next = "select a.blogid as id from pre_home_blog as a,pre_home_blogfield as b where a.blogid>=".$end.' order by a.blogid asc limit 1';
	global $mod_1,$mod_2,$mod_3,$mod_4,$mod_5,$endid;
	if(isEnd($Operate,$sql_next)){
		if($endidtemp!=0)write_spider_config($mod_1,$mod_2,$endidtemp,$mod_4,$mod_5);
		return false;
	}else{
		if($endid!=0)write_spider_config($mod_1,$mod_2,$endid,$mod_4,$mod_5);
		return true;
	}
}
//相册
function spiderAlbum($start,$end,$action='add'){
	$Operate=new Operate();
	$Operate -> connect('127.0.0.1','root','root','bbs',1,'gbk');
	$result=$Operate->get_all("select * from pre_home_album where albumid>=".$start." and albumid<".$end);
	$format = new format();
	$array = new ArraySet();
	$endidtemp = 0;
	for($i=0;$i<count($result);$i++){
		$linkVO = new LinkVO();
		$linkVO -> setTitle($format -> removeHtml(mb_convert_encoding($result[$i]['albumname'],'utf-8','gbk').'-'.mb_convert_encoding($result[$i]['username'],'utf-8','gbk')));
		$linkVO -> setContent($format -> removeHtml('相片数量：'.mb_convert_encoding($result[$i]['picnum'],'utf-8','gbk')));
		$linkVO -> setUrl('http://www.i-bei.com/baby/home.php?mod=space&uid='.mb_convert_encoding($result[$i]['uid'],'utf-8','gbk').'&do=album&id='.mb_convert_encoding($result[$i]['albumid'],'utf-8','gbk'));
		$linkVO -> setTime($result[$i]['dateline']);
		$linkVO -> setMod(4);
		$array -> add($linkVO);
		$endidtemp = $result[$i]['albumid'];
	}
	$linkBiz = new LinkBiz();
	if($action=='add'){
		$linkBiz -> addArraySet($array);
	}else{
		$linkBiz -> updateArraySet($array);
	}
	$sql_next = "select albumid as id from pre_home_album where albumid>=".$end.' order by albumid asc limit 1';
	global $mod_1,$mod_2,$mod_3,$mod_4,$mod_5,$endid;
	if(isEnd($Operate,$sql_next)){
		if($endidtemp!=0)write_spider_config($mod_1,$mod_2,$mod_3,$endidtemp,$mod_5);
		return false;
	}else{
		if($endid!=0)write_spider_config($mod_1,$mod_2,$mod_3,$endid,$mod_5);
		return true;
	}
}

//圈子
function spiderGroup($start,$end,$action='add'){
	$Operate=new Operate();
	$Operate -> connect('127.0.0.1','root','root','bbs',1,'gbk');
	$result=$Operate->get_all("select * from pre_forum_forum as a ,pre_forum_forumfield as b where a.status=3 and a.fid=b.fid and a.fid>=".$start." and a.fid<".$end);
	$format = new format();
	$array = new ArraySet();
	$endidtemp = 0;
	for($i=0;$i<count($result);$i++){
		$linkVO = new LinkVO();
		$linkVO -> setTitle($format -> removeHtml(mb_convert_encoding($result[$i]['name'],'utf-8','gbk')));
		$linkVO -> setContent($format -> removeHtml(mb_convert_encoding($result[$i]['description'],'utf-8','gbk')));
		$linkVO -> setUrl('http://www.i-bei.com/baby/group-'.mb_convert_encoding($result[$i]['fid'],'utf-8','gbk').'-1.html');
		$linkVO -> setTime($result[$i]['dateline']);
		$linkVO -> setMod(5);
		$array -> add($linkVO);
		$endidtemp = $result[$i]['fid'];
	}
	$linkBiz = new LinkBiz();
	if($action=='add'){
		$linkBiz -> addArraySet($array);
	}else{
		$linkBiz -> updateArraySet($array);
	}
	$sql_next = "select a.fid as id from pre_forum_forum as a ,pre_forum_forumfield as b where a.status=3 and a.fid=b.fid and a.fid>=".$end.' order by a.fid asc limit 1';
	global $mod_1,$mod_2,$mod_3,$mod_4,$mod_5,$endid;
	if(isEnd($Operate,$sql_next)){
		if($endidtemp!=0)write_spider_config($mod_1,$mod_2,$mod_3,$mod_4,$endidtemp);
		return false;
	}else{
		if($endid!=0)write_spider_config($mod_1,$mod_2,$mod_3,$mod_4,$endid);
		return true;
	}
}
?>